import request from '../utils/request';
import { PAGE_SIZE } from '../constants';

export function fetchAll({ daoName, where }) {
  let data = new FormData()
  data.append("where", where)
  return request(`/api/restricted/FindAll/${daoName}`, {
    method: 'POST',
    body: data,
  });
}

export function fetch({ daoName, page, pageSize, sorter, filters, permID }) {
  let data = new FormData()
  if (sorter && sorter.length > 0) {
    data.append("OrderItems", JSON.stringify(sorter))
  }
  if (filters && filters.length > 0) {
    data.append("WhereCauses", JSON.stringify(filters))
  }
  data.append("PermID", "" + permID)
  return request(`/api/restricted/Find/${daoName}/${page}/${pageSize}`, {
    method: 'POST',
    body: data,
  });
}

export function fetchOption({ daoName, where }) {
  let data = new FormData()
  data.append("where", where)
  return request(`/api/restricted/FindAll/${daoName}`, {
    method: 'POST',
    body: data
  });
}

export function fetchOption2({ daoName, where }) {
  let data = new FormData()
  data.append("where", where)
  return request(`/api/FindAll/${daoName}`, {
    method: 'POST',
    body: data
  });
}


export function removeKeys({ daoName, keys }) {
  var data = new FormData()
  data.append('PrimaryKeyValues', JSON.stringify(keys))
  return request(`/api/restricted/Deletes/${daoName}`, {
    method: 'POST',
    body: data
  });
}

export function removeEntity({ daoName, values }) {
  var data = new FormData()
  data.append('Entity', JSON.stringify(values))
  return request(`/api/restricted/Delete/${daoName}`, {
    method: 'POST',
    body: data
  });
}

export function patch({ daoName, values }) {
  var data = new FormData()
  data.append('Entity', JSON.stringify(values))
  return request(`/api/restricted/Update/${daoName}`, {
    method: 'POST',
    body: data,
  });
}

export function create({ daoName, values }) {
  var data = new FormData()
  data.append('Entity', JSON.stringify(values))
  return request(`/api/restricted/Add/${daoName}`, {
    method: 'POST',
    body: data,
  });
}

export function submitDatas({ daoName, newDatas, updateDatas, deleteDatas }) {
  var data = new FormData()
  data.append('NewDatas', JSON.stringify(newDatas))
  data.append('UpdateDatas', JSON.stringify(updateDatas))
  data.append('DeleteDatas', JSON.stringify(deleteDatas))
  return request(`/api/restricted/SaveDatas/${daoName}`, {
    method: 'POST',
    body: data,
  });     
}

export function setUseLog({ key }) {
  var data = new FormData()
  data.append('key', key)
  return request(`/api/restricted/UseLog`, {
    method: 'POST',
    body: data,
  });
}

//对公汇总流程
export function execproc({}) {      
  var data = new FormData()
  return request(`/api/restricted/Execproc`, {        
    method: 'POST',
    body: data,
  });
}

//零售汇总流程
export function execindi({}) {
  var data = new FormData()
  return request(`/api/restricted/Execindi`, {
    method: 'POST',
    body: data,
  });
}

//零售新客户申请相关客户经理审批
// export function IndiClieDiviFlowNewApp({ emid1, emid2, emid3,frid }) {
//   var data = new FormData()
//   data.append('emid1', emid1)
//   data.append('emid2', emid2)
//   data.append('emid3', emid3)
//   data.append('frid', frid)
//   return request(`/api/restricted/IndiClieDiviFlowNewApp`, {
//     method: 'POST',
//     body: data,
//   });
// }
//零售客户变更相关客户经理审批
// export function IndiClieDiviFlowUpdateApp({ emid1, emid2, emid3,frid }) {
//   var data = new FormData()
//   data.append('emid1', emid1)
//   data.append('emid2', emid2)
//   data.append('emid3', emid3)
//   data.append('frid', frid)
//   return request(`/api/restricted/IndiClieDiviFlowUpdateApp`, {
//     method: 'POST',
//     body: data,
//   });
// }

// //公司客户变更相关客户经理审批
// export function CompClieDiviFlowUpdate({ emid1, emid2, emid3,frid }) {
//   var data = new FormData()
//   data.append('emid1', emid1)
//   data.append('emid2', emid2)
//   data.append('emid3', emid3)
//   data.append('frid', frid)
//   return request(`/api/restricted/CompClieDiviFlowUpdate`, {
//     method: 'POST',
//     body: data,
//   });
// }


